package jnpf.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jnpf.base.service.BillRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.base.UserInfo;
import jnpf.base.vo.DownloadVO;
import jnpf.config.ConfigValueUtil;
import jnpf.exception.DataException;
import org.springframework.transaction.annotation.Transactional;
import jnpf.base.entity.ProvinceEntity;
import jnpf.model.whu_interviewrecord.*;
import jnpf.model.whu_interviewrecord.Whu_interviewrecordPagination;
import jnpf.permission.entity.UserEntity;
import jnpf.permission.service.UserService;
import jnpf.model.whu_interviewrecord.Whu_interviewrecordCrForm;
import jnpf.model.whu_interviewrecord.Whu_interviewrecordInfoVO;
import jnpf.model.whu_interviewrecord.Whu_interviewrecordListVO;
import jnpf.model.whu_interviewrecord.Whu_interviewrecordUpForm;
import jnpf.entity.*;
import jnpf.base.service.ProvinceService;
import jnpf.util.*;
import jnpf.base.util.*;
import jnpf.base.vo.ListVO;
import jnpf.util.context.SpringContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import jnpf.entity.Whu_interviewrecordEntity;
import jnpf.service.Whu_interviewrecordService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;


/**
 *
 * whu_interviewrecord
 * @版本： V3.2.0
 * @版权： 引迈信息技术有限公司（https://www.jnpfsoft.com）
 * @作者： JNPF开发平台组
 * @日期： 2025-06-30
 */
@Slf4j
@RestController
@Api(tags = "whu_interviewrecord" , value = "system")
@RequestMapping("/api/system/Whu_interviewrecord")
public class Whu_interviewrecordController {


    @Autowired
    private GeneraterSwapUtil generaterSwapUtil;
    @Autowired
    private UserService userService;
    @Autowired
    private UserProvider userProvider;

    @Autowired
    private Whu_interviewrecordService whu_interviewrecordService;



    /**
     * 列表
     *
     * @param whu_interviewrecordPagination
     * @return
     */
    @PostMapping("/getList")
    public ActionResult list(@RequestBody Whu_interviewrecordPagination whu_interviewrecordPagination) throws IOException {
        List<Whu_interviewrecordEntity> list = whu_interviewrecordService.getList(whu_interviewrecordPagination);
        //处理id字段转名称，若无需转或者为空可删除
        for (Whu_interviewrecordEntity entity : list) {
            entity.setUserid(generaterSwapUtil.userSelectValue(entity.getUserid()));
        }
        List<Whu_interviewrecordListVO> listVO = JsonUtil.getJsonToList(list, Whu_interviewrecordListVO.class);
        for (Whu_interviewrecordListVO whu_interviewrecordVO : listVO) {
        }


        PageListVO vo = new PageListVO();
        vo.setList(listVO);
        PaginationVO page = JsonUtil.getJsonToBean(whu_interviewrecordPagination, PaginationVO.class);
        vo.setPagination(page);
        return ActionResult.success(vo);
    }


    /**
     * 创建
     *
     * @param whu_interviewrecordCrForm
     * @return
     */
    @PostMapping
    @Transactional
    public ActionResult create(@RequestBody @Valid Whu_interviewrecordCrForm whu_interviewrecordCrForm) throws DataException {
        String mainId =RandomUtil.uuId();
        UserInfo userInfo=userProvider.get();
        whu_interviewrecordCrForm.setTodate(DateUtil.getNow());
        whu_interviewrecordCrForm.setUserid(userInfo.getUserId());
        Whu_interviewrecordEntity entity = JsonUtil.getJsonToBean(whu_interviewrecordCrForm, Whu_interviewrecordEntity.class);
        entity.setId(mainId);
        whu_interviewrecordService.save(entity);


        return ActionResult.success("创建成功");
    }




    /**
     * 信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ActionResult<Whu_interviewrecordInfoVO> info(@PathVariable("id") String id){
        Whu_interviewrecordEntity entity= whu_interviewrecordService.getInfo(id);
        Whu_interviewrecordInfoVO vo=JsonUtil.getJsonToBean(entity, Whu_interviewrecordInfoVO.class);
        if(vo.getTodate()!=null){
            vo.setTodate(vo.getTodate());
        }
        if(StringUtil.isNotEmpty(entity.getUserid())){
            UserEntity userEntity=userService.getInfo(entity.getUserid());
            vo.setUserid(userEntity.getRealName()+"/"+userEntity.getAccount());
        }

        return ActionResult.success(vo);
    }





    /**
     * 更新
     *
     * @param id
     * @return
     */
    @PutMapping("/{id}")
    @Transactional
    public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid Whu_interviewrecordUpForm whu_interviewrecordUpForm) throws DataException {
        UserInfo userInfo=userProvider.get();
        Whu_interviewrecordEntity entity= whu_interviewrecordService.getInfo(id);
        if(entity!=null){
            Whu_interviewrecordEntity subentity=JsonUtil.getJsonToBean(whu_interviewrecordUpForm, Whu_interviewrecordEntity.class);
            subentity.setTodate(entity.getTodate());
            subentity.setUserid(entity.getUserid());
            whu_interviewrecordService.update(id, subentity);
            return ActionResult.success("更新成功");
        }else{
            return ActionResult.fail("更新失败，数据不存在");
        }
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @Transactional
    public ActionResult delete(@PathVariable("id") String id){
        Whu_interviewrecordEntity entity= whu_interviewrecordService.getInfo(id);
        if(entity!=null){
            whu_interviewrecordService.delete(entity);

        }
        return ActionResult.success("删除成功");
    }


}
